// 首页
import { song,getcommodity,getrecommend,recommendabout } from "@/api/song.js"

// 购物车
import { getshopcar,addshopcar,deleteshopcar,alldeleteshopcar } from "@/api/song.js"

// 分类
import { getmaccommodity } from '@/api/song.js'

// 登录
import {login} from '@/api/song.js'

// 搜索
import {search} from '@/api/song.js'

// 设置属性值
const state=
{
	songdata:'',
	commodity:'',
	recommend:'',
	about:'',
	
	getshopcar:'',
	addshopcar:'',
	deleteshopcar:'',
	
	maccommodity:'',
	
	username:'',
	
	searchdata:'',
	
	deleteall:''
}

// 修改属性值
const mutations=
{
	set_song:(state,data)=>
	{
		state.songdata=data
	},
	set_commodity:(state,data)=>
	{
		state.commodity=data
	},
	set_recommend:(state,data)=>
	{
		state.recommend=data
	},
	set_about:(state,data)=>
	{
		state.about=data
	},
	set_getShopCar:(state,data)=>
	{
		state.getshopcar=data
	},
	set_addShopCar:(state,data)=>
	{
		state.addshopcar=data
	},
	set_maccommodity:(state,data)=>
	{
		state.maccommodity=data
	},
	set_login:(state,data)=>
	{
		state.username=data
	},
	set_search:(state,data)=>
	{
		state.searchdata=data
	},
	set_deleteshopcar:(state,data)=>
	{
		state.deleteshopcar=data
	},
	set_alldeleteshopcar:(state,data)=>
	{
		state.deleteall=data
	},
}

// 调用mutations方法
const actions=
{
	vuexSong({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var songState=song()
			if(songState)
			{
				commit("set_song",songState+data)
				resolve(songState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	vuexCommodity({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var commodityState=getcommodity()
			if(commodityState)
			{
				commit("set_commodity",commodityState+data)
				resolve(commodityState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	vuexRecommend({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var recommendState=getrecommend()
			if(recommendState)
			{
				commit("set_recommend",recommendState+data)
				resolve(recommendState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	vuexAbout({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var aboutState=recommendabout(data)
			if(aboutState)
			{
				commit("set_about",aboutState+data)
				resolve(aboutState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	vuexMacCommodity({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var macCommodityState=getmaccommodity(data)
			if(macCommodityState)
			{
				commit("set_maccommodity",macCommodityState+data)
				resolve(macCommodityState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	vuexLogin({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var loginState=login(data)
			if(loginState)
			{
				commit("set_login",loginState+data)
				resolve(loginState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	vuexSearch({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var searchState=search(data)
			if(searchState)
			{
				commit("set_search",searchState+data)
				resolve(searchState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	// 获取购物车
	vuexGetShopCar({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var getshopcarState=getshopcar(data)
			if(getshopcarState)
			{
				commit("set_getShopCar",getshopcarState+data)
				resolve(getshopcarState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	
	// 添加购物车
	vuexAddShopCar({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var addshopcarState=addshopcar(data)
			if(addshopcarState)
			{
				commit("set_addShopCar",addshopcarState+data)
				resolve(addshopcarState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	
	// 删除购物车
	vuexDeleteShopCar({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var deleteshopcarState=deleteshopcar(data)
			if(deleteshopcarState)
			{
				commit("set_deleteshopcar",deleteshopcarState+data)
				resolve(deleteshopcarState)
			}
			else
			{
				reject('失败')
			}
		})
	},
	
	// 清空购物车
	vuexAllDeleteShopCar({commit},data)
	{
		return new Promise((resolve,reject)=>
		{
			var alldeleteshopcarState=alldeleteshopcar(data)
			if(alldeleteshopcarState)
			{
				commit("set_alldeleteshopcar",alldeleteshopcarState+data)
				resolve(alldeleteshopcarState)
			}
			else
			{
				reject('失败')
			}
		})
	},
}

// 导出
export default
{
	// 是否使用
	namespaced:true,
	state,
	mutations,
	actions
}